﻿using System;
using System.Text;
using System.Collections.Generic;

namespace DreamCube.Framework.Utilities.Report
{
    /// <summary>
    /// 可以包含子元素的元素基类
    /// </summary>
    public class ElementContainer : Element
    {
        #region "字段"

        protected List<Element> elements = new List<Element>();

        #endregion

        #region "属性"

        /// <summary>
        /// 表单中的元素
        /// </summary>
        public List<Element> Elements
        {
            get { return elements; }
            set { this.elements = value; }
        }

        #endregion

        #region "方法"

        /// <summary>
        /// 根据ID获取元素
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Element GetElementByID(String id)
        {
            for (Int32 i = 0; i < elements.Count; i++)
            {
                if (elements[i].ElementID == id)
                    return ElementHelper.Create(elements[i]);
            }
            return null;
        }

        /// <summary>
        /// 生成报表HTML
        /// </summary>
        public override String ToHtml()
        {
            StringBuilder html = new StringBuilder();
            for (Int32 i = 0; i < elements.Count; i++)
            {
                Element e = ElementHelper.Create(elements[i]);
                if (e != null) html.Append(e.ToHtml());
            }
            return html.ToString();
        }

        #endregion
    }
}
